package com.cssl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cssl.pojo.Classification;
import com.cssl.pojo.Location;
import com.cssl.service.ClassificationService;
import com.cssl.service.LocationService;
import com.cssl.vo.ClassificationVo;
import com.cssl.vo.LocationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ClassificationController {
    @Autowired
    private ClassificationService cservice;

    @PostMapping("/pageclassification")
    public ClassificationVo pageclassification(Integer current, Integer size){
        if (current==null||current<1){
            current=1;
        }
        if(size==null||size<1){
            size=3;
        }
        ClassificationVo classificationVo=new ClassificationVo();
        IPage<Classification> page=new Page<>(current,size);
        cservice.page(page,null);
        classificationVo.setCurrent(current);
        classificationVo.setSize(size);
        classificationVo.setTotal(page.getTotal());
        classificationVo.setUserList(page.getRecords());
        classificationVo.setCount(page.getPages());
        return classificationVo;
    }

    //添加
    @PostMapping("/addcf")
    public boolean addcf(Classification cf){
        return cservice.save(cf);
    }

    //按id查询
    @PostMapping("/selcid")
    public Classification selcid(Integer cid){
        return cservice.getBaseMapper().selectById(cid);
    }

    //按id修改
    @PostMapping("/updcid")
    public boolean updcid(Classification cf){
        return cservice.updateById(cf);
    }


    //按id删除
    @PostMapping("/delcid")
    public int delcid(Integer cid){
        return cservice.getBaseMapper().deleteById(cid);
    }
}
